package com.jrx.anytxn.customer.dto.customer.medical;

import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.exception.TxnRuntimeException;
import com.jrx.anytxn.param.constant.Constant;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 信用就医业务，cms客户端发起冻结、解冻操作处理结果返回
 *
 * @author user
 * @date 2022/8/9 14:30
 */
public class CustomerUseLimitFrozeFrozeReq extends CustomerLimitFrozeBaseReq implements Serializable {
    private static final long serialVersionUID = -7052966390686842001L;

    /**
     * 商户号
     * 表字段:merchantNo
     */
    @ApiModelProperty(value = "商户号", example = "1X1Z22")
    @Size(max = 32, message = "商户号merchantNo长度不能大于32位")
    private String merchantNo;

    /**
     * 额度的占用恢复标识
     * 表字段:useResumeFlag
     */
    @ApiModelProperty(value = "额度占用恢复标识", example = "U")
    @Size(max = 1, message = "U----额度占用，R----额度恢复")
    @NotBlank(message = "额度占用恢复标识(U----额度占用，R----额度恢复)  不能为空")
    private String useResumeFlag;

    /**
     * 冻结流水号
     * 表字段:froze_no
     */
    @ApiModelProperty(value = "冻结流水号", example = "KPIS12354")
    @NotBlank(message = "冻结流水号不能为空")
    private String frozeNo;

    /**
     * 支付流水号
     */
    @ApiModelProperty(value = "支付流水号", example = "KPIS12354")
    @NotBlank(message = "支付流水号不能为空")
    @Length(max = 64, message = "支付流水号长度不能超过64")
    private String serialNo;
    /**
     * 支付补充信息
     */
    @ApiModelProperty(value = "支付补充信息", example = "挂号费用")
    private String useDesc;

    /**
     * 冻结流水号对应的使用金额
     */
    @ApiModelProperty(value = "冻结流水号对应的使用金额", example = "100.22")
    private BigDecimal useAmount;

    public String getMerchantNo() {
        return merchantNo;
    }

    public void setMerchantNo(String merchantNo) {
        this.merchantNo = merchantNo;
    }

    public String getFrozeNo() {
        return frozeNo;
    }

    public void setFrozeNo(String frozeNo) {
        this.frozeNo = frozeNo;
    }

    public BigDecimal getUseAmount() {
        return useAmount;
    }

    public void setUseAmount(BigDecimal useAmount) {
        this.useAmount = useAmount;
    }

    public String getSerialNo() {
        return serialNo;
    }

    public void setSerialNo(String serialNo) {
        this.serialNo = serialNo;
    }

    public String getUseDesc() {
        return useDesc;
    }

    public void setUseDesc(String useDesc) {
        this.useDesc = useDesc;
    }

    public String getUseResumeFlag() {
        return useResumeFlag;
    }

    public void setUseResumeFlag(String useResumeFlag) {
        this.useResumeFlag = useResumeFlag;
    }

    public void check() {
        if (!(Constant.USE_RESUME_FLAG_R.equals(this.useResumeFlag) || Constant.USE_RESUME_FLAG_U.equals(this.useResumeFlag))) {
            throw new TxnRuntimeException(TxnRespCode.PARAM_ERROR.getCode(), "额度恢复/占用处理，恢复、占用标识不正确；U----额度占用，R----额度恢复");
        }
        if (Constant.USE_RESUME_FLAG_U.equals(this.useResumeFlag) && this.useAmount == null) {
            throw new TxnRuntimeException(TxnRespCode.PARAM_ERROR.getCode(), "额度占用处理，金额不能为空");
        }
        if (this.useAmount != null) {
            if (this.useAmount.signum() < 1) {
                throw new TxnRuntimeException(TxnRespCode.PARAM_ERROR.getCode(), "金额必须为正值");
            }
            this.useAmount = useAmount.setScale(2, BigDecimal.ROUND_HALF_UP);
        }
    }
}
